﻿using H2.NET.Common;
using H2.NET.Web.Pages.SMD.Helper;
using H2.NET.Web.Pages.SMD.Model;
using H2.NET.Web.Pages.SMD.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace H2.NET.Web.Pages.SMD
{
    public partial class uc_change_field : TaskControl
    {
        public string AssessmentID
        {
            get
            {
                return ViewState["AssessmentID"] == null ? "" : ViewState["AssessmentID"].ToString();
            }
            set
            {
                ViewState["AssessmentID"] = value;
            }
        }
        public List<string> AssessmentIDs
        {
            get
            {
                return ViewState["AssessmentIDs"] == null ? new List<string>() : (List<string>)ViewState["AssessmentIDs"];
            }
            set
            {
                ViewState["AssessmentIDs"] = value;
            }
        }

        public List<t_StoreDataChangeLog> StoreDataChangeLogs
        {
            get
            {
                return ViewState["StoreDataChangeLogs"] == null ? new List<t_StoreDataChangeLog>() : (List<t_StoreDataChangeLog>)ViewState["StoreDataChangeLogs"];
            }
            set
            {
                ViewState["StoreDataChangeLogs"] = value;
            }
        }

        public bool IsDistinct
        {
            get
            {
                return ViewState["IsDistinct"] == null ? true : (bool)ViewState["IsDistinct"];
            }
            set
            {
                ViewState["IsDistinct"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IList<t_StoreDataChangeLog> changeLogs = (t_StoreDataChangeLog._AssessmentID == AssessmentID).List<t_StoreDataChangeLog>();

                if (AssessmentIDs != null && AssessmentIDs.Count > 0)
                {
                    if (IsDistinct)
                    {
                        changeLogs = ChangeLogService.GetLastChangeLogs(AssessmentIDs);
                    }
                    else
                    {
                        changeLogs = ChangeLogService.GetChangeLogs(AssessmentIDs);
                    }
                }

                StoreDataChangeLogs = changeLogs.ToList();

                ChangeLogService.FormatChangeLogs(changeLogs.ToList());
                
                rpt_change_logs.DataSource = changeLogs;
                rpt_change_logs.DataBind();
            }
        }
    }
}